package top.zhangjianyong.tools.utils;

import lombok.Data;

/**
 * @author ： zhangjianyong
 * @date ： 2021/11/1 15:27
 */
@Data
public class ApiResponse {
    private Integer code;
    private String message;
    private Object data;

    public static ApiResponse success() {
        ApiResponse apiResponse = new ApiResponse();
        apiResponse.setCode(200);
        apiResponse.setMessage("成功");
        return apiResponse;
    }

    public static ApiResponse success(Object t) {
        ApiResponse success = success();
        success.setData(t);
        return success;
    }

    public static ApiResponse fail(Integer code, String message, Object data) {
        ApiResponse apiResponse = new ApiResponse();
        apiResponse.setCode(code);
        apiResponse.setMessage(message);
        apiResponse.setData(data);
        return apiResponse;
    }

    public static ApiResponse fail(Integer code, String message) {
        return fail(code, message, null);
    }

    public static ApiResponse fail(String message) {
        return fail(message, null);
    }

    public static ApiResponse fail(String message, Object date) {
        return fail(500, message, date);
    }
}
